<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>首页</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
	<link href="./css/mui.css" rel="stylesheet"/>
	<link href="./css/mui.min.css" rel="stylesheet"/>
	<link href="./css/mui-icons-extra.css" rel="stylesheet"/>
	<link href="./css/app.css" rel="stylesheet"/>
	<style type="text/css">
	</style>
</head>
<body>
	<!-- 头部HEADER -->
	<header class="app-header">
		<b>最新</b>
		&nbsp; &nbsp; 
		<span onclick="jumpToIndexHistory()">足迹</span>
	</header>
	<!-- 头部HEADER -->
	
	<!-- 首页视频布局 -->
	<div class="app-video-bg" id="refresh">
		<div class="app-video" id="vvv">
			<video poster="./files/imgs/tmp.png" src="./files/videos/001.mp4" type="video/mp4" name="media" controls="controls" autoplay="autoplay" loop id="video-1" class="app-video-tag"></video>
		</div>
		<button type="button" onclick="createDownload()">下载</button>
		<button type="button" onclick="clearFiles()">清理</button>
		<textarea id="vtmp" style="width:100%;"></textarea>
	</div>
	<!-- 首页视频布局 -->
	
	<!-- 底部菜单 -->
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item mui-active" onclick="jumpToIndex()">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">库</span>
		</a>
<!-- 		<a class="mui-tab-item" onclick="jumpToChat()">
			<span class="mui-icon mui-icon-chatbubble"></span>
			<span class="mui-tab-label">消息</span>
		</a> -->
		<a class="mui-tab-item" onclick="jumpToMy()">
			<span class="mui-icon mui-icon-contact"></span>
			<span class="mui-tab-label">我的</span>
		</a>
	</nav>
	<!-- 底部菜单 -->
</body>
</html>


<script src="./js/mui.js"></script>
<script src="./js/mui.min.js"></script>
<script src="./js/app.js"></script>
<script type="text/javascript">
	// 先下载数据
	function getIndex(){}
	// 再下载文件
	// 下面是下载文件的处理
	var fname = '001.mp4';
	var fpath = 'http://tsh.fuzhuangchangongxiao.cn/uploads/20200221/'+fname;
	// 判断下载
	function createDownload(){
		mui.plusReady(function () {
			//判断文件是否已经下载
			plus.io.resolveLocalFileSystemURL(
				'_downloads/'+fname,
				function(entry){
					if(entry.isFile){
						mui('#vvv')[0].innerHTML = '<video poster="" src="'+entry.fullPath+'" type="video/mp4" name="media" controls="controls" autoplay="autoplay" loop id="video-1" class="app-video-tag"></video>/>';
						mui('#vtmp')[0].innerHTML = entry.fullPath; 
						mui.toast(entry.fullPath+'已经下载');
					}
				},
				// mui.toast('11')
				function(e){dBase();}
			);
		})
	}
	// 下载动作
	function dBase(){
	    dtask = plus.downloader.createDownload(
	        fpath,
	        {method:"GET"},
	        //下载完成执行的回调函数
	        function(d, status){
				mui('#vvv')[0].innerHTML = '<video poster="" src="'+d.filename+'" type="video/mp4" name="media" controls="controls" autoplay="autoplay" loop id="video-1" class="app-video-tag"></video>';
				mui('#vtmp')[0].innerHTML = task.filename;
	            mui.toast(d.filename);
	        }
	    );
	    dtask.addEventListener("statechanged", function(task,status){
	        if(!dtask){return;}
	        switch(task.state) {
	            case 1: // 开始
	                mui.toast("开始下载...");
	            break;
	            case 2: // 已连接到服务器
	                mui.toast( "链接到服务器...");
	            break;
	            case 3:    // 已接收到数据
					mui.toast((task.downloadedSize/task.totalSize)*100+'%');
	            break;
	            case 4:    // 下载完成
					mui('#vvv')[0].innerHTML = '<video poster="" src="'+task.filename+'" type="video/mp4" name="media" controls="controls" autoplay="autoplay" loop id="video-1" class="app-video-tag"></video>';
					mui('#vtmp')[0].innerHTML = task.filename;
	                mui.toast( "下载完成！");
	            break;
	        }
	    });
	    dtask.start();
	}
	// 清理缓存
	function clearFiles(){
		mui.toast('开始清理。。')
		mui.plusReady(function(){
			var localUrl = '_downloads/'+fname; //本地文件地址
			plus.io.resolveLocalFileSystemURL(
				localUrl, 
				function(entry){
					// entry.removeRecursively(function(entry){
					// 	mui.toast("删除成功!");
					// 	plus.console.log("Remove succeeded");
					// }, function (e) {
					// 	mui.toast(e.message);
					// } 
					entry.remove(function(){
						mui.toast('删除成功');
					});
				}
			);
		});
	}
</script>